package com.xinqi.modules.sys.config.controller;

import com.xinqi.common.base.response.R;
import com.xinqi.common.core.constant.ConfigKeyConstants;
import com.xinqi.common.core.web.controller.BaseController;
import com.xinqi.modules.sys.config.domain.SysConfig;
import com.xinqi.modules.sys.config.service.ISysConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 参数配置 信息操作处理
 *
 * @author dgyu
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/config")
public class SysConfigController extends BaseController {

    private final ISysConfigService configService;


    /**
     * 获取云课本开关
     */
    @GetMapping(value = "/cloud-note/open")
    public R<String> getConfigKey() {
        String configKey = ConfigKeyConstants.SYS_CLOUD_NOTE_OPEN;
        return R.data(configService.selectConfigByKey(configKey), "获取成功");
    }

    /**
     *  更新云课本开关
     */
    @PostMapping(value = "/cloud-note/switch")
    public R<String> refreshConfigKey(@RequestBody SysConfig sys) {
        return R.ok(configService.updateConfig(sys));
    }

    /**
     * 获取客服机器人地址
     */
    @GetMapping(value = "/robot/address")
    public R<String> getRobotAddress() {
        String configKey = ConfigKeyConstants.SYS_SERVICE_ROBOT_ADDRESS;
        return R.data(configService.selectConfigByKey(configKey), "获取成功");
    }

    /**
     * 参数配置 -- 开关
     *
     * @param configKey
     * @return
     */
    @GetMapping(value = "/configKey/{configKey}")
    public R<String> getConfigKey(@PathVariable("configKey") String configKey) {
        return R.data(configService.selectConfigByKey(configKey), "获取成功");
    }

}
